package com.beiing.tianshuai.tianshuai.freshnews.presenter;

import com.beiing.tianshuai.tianshuai.base.BasePresenter;
import com.beiing.tianshuai.tianshuai.entity.CodeBean;
import com.beiing.tianshuai.tianshuai.freshnews.model.DiscoveryPublishModel;
import com.beiing.tianshuai.tianshuai.freshnews.model.DiscoveryPublishModelImpl;
import com.beiing.tianshuai.tianshuai.freshnews.view.DiscoveryPublishViewImpl;

import java.io.File;

import okhttp3.ResponseBody;

/**
 * Created by Jinni on 2017/9/15 0015.
 */

public class DiscoveryPublishPresenter extends BasePresenter implements DiscoveryPublishPresenterImpl, DiscoveryPublishModel.OnRequestResult {

    private DiscoveryPublishViewImpl mView;
    private DiscoveryPublishModelImpl mModel;

    public DiscoveryPublishPresenter(DiscoveryPublishViewImpl view) {
        mView = view;
        mModel = new DiscoveryPublishModel(this);
    }

    @Override
    public void getPublishResult(String content, String uid, String title, String freshCover) {
        mView.showProgress();
        mModel.getPublishResult(content, uid, title, freshCover);
    }

    @Override
    public void getUploadImg(File file) {
        mView.showProgress();
        mModel.getUploadImg(file);
    }

    @Override
    public void onSuccess(CodeBean bean) {
        mView.hideProgress();
        mView.onRequestSuccess(bean);
    }

    @Override
    public void onUploadSuccess(ResponseBody body) {
        mView.hideProgress();
        mView.getUploadResult(body);
    }

    @Override
    public void onError(Throwable throwable, int i) {
        mView.hideProgress();
        mView.onRequestFailed(throwable, i);
    }
}
